import 'm3u8_download_notify_state.dart';

///
/// 当state为 [M3u8DownloadNotifyState.downloading]时，才可能有downloadedTime和totalTime, 其余时候没有这两个值
/// 当state为 [M3u8DownloadNotifyState.downloading]时，downloadedTime和totalTime 也可能没值
/// 当downloadedTime 有可能会大于totalTime, 这时不认为下载完成， 只有当state为 [M3u8DownloadNotifyState.success] 才认为完成
///

class M3u8DownloadNotify {
  M3u8DownloadNotifyState state;
  double? downloadedTime;
  double? totalTime;

  double? get progress {
    if (downloadedTime == null || totalTime == null) return 0;
    if (totalTime == 0) return null;
    final v = downloadedTime! / totalTime!;
    if (v < .0) return null;
    if (v >= 1.0) return 0.99999999; // 这里不返回1， 在onSuccess中处理
    return v;
  }

  M3u8DownloadNotify(this.state, {this.downloadedTime, this.totalTime});
}
